function Harmonogram() {
	return {
		createDeleteWindow: function(id) {
			$('<div>').simpledialog2({
			    mode: 'button',
			    headerText: 'Pytanie',
			    headerClose: false,
			    buttonPrompt: 'Czy na pewno chcesz usunąć wybrany harmonogram ?',
			    buttons : {
			      'Tak': {
			        click: function () { 
						App.doGetRequestText({
							url: 'harmonogram!delete.action?harmonogramId=' + id,
							onSucces: function(response) {
								$('<div>').simpledialog2({
								    mode: 'blank',
								    headerText: 'Informacja',
								    headerClose: true,
								    blankContent : '<div style="padding: 20px"><p>' + response + '</p><a rel="close" data-role="button" href="#">Zamknij</a></div>',
								    width: 200
					  			})
							}
						});	
			        }
			      },
			      'Nie': {
			        click: function () { 
			        	window.location.reload();
			        },
			        icon: "delete",
			        theme: "c"
			      }
			    }
			  });
		},
		createEditWindow: function(id) {
			App.doGetRequestText({
				url: 'harmonogram!edit.action?harmonogramId=' + id,
				onSucces: function(response) {
					$('<div>').simpledialog2({
					    mode: 'blank',
					    headerText: 'Edycja harmonogramu',
					    headerClose: false,
					    blankContent : response.replace(/\\n/g, ''),
					    fullScreen: true,
						fullScreenForce: true
		  			})
				}
			});
		},
		createList: function(config) {
			var thisObj = this;
			App.doGetRequestJson({
				url: config.url,
		 		onSucces: function(response) {
					var html ='';
				    $.each(response, function(index, item) {
				    	html += '<li data-role="list-divider" ><h1>' + item.data + ''
				    	+ ' ( ' + item.godzinaPoczatkowa + ' - ' + item.godzinaKoncowa
				    	+ ' )</li></h1>';
				    	html += '<li>';
				    	
				    	if (!jQuery.isEmptyObject(item.placManewrowy)) {
				    		html += '<h2><strong>Plac manewrowy:</strong></h2>';
				    		html += '<p>Od: <strong>' + item.placManewrowy.godzinaPoczatkowa + 'h</strong> do <strong>' + item.placManewrowy.godzinaKoncowa + 'h</strong> </p>';
				    	}
				    	
				    	if (!jQuery.isEmptyObject(item.kursanci)) {
				    		html += '<h3><strong>Kursanci:</strong></h3>';
				    		$.each(item.kursanci, function(index, value) { 
				    			html += '<p>' + value.kursant.imie + ' ' + value.kursant.nazwisko + '</p>';
				    		});
				    	}
				    	html += '<p class="ui-li-aside">';
					    html += '<select name="actionButton" id="actionButton' + item.id + '" data-theme="a" data-icon="gear" data-inline="true" data-native-menu="false">';
					    html += '<option value="0" data-placeholder="true">Operacje</option>';
					    html += '<option value="edit">Edytuj</option><option value="delete">Usuń</option>';
						html += '</select></p>';
						
				    });

				    html += '</li>';

					$('#' + config.listId).empty();
					$('#' + config.listId).append($(html));
					$('#' + config.listId).trigger('create');
					$('#' + config.listId).listview('refresh');
					
					$.each(response, function(index, item) {
						$("#actionButton" + item.id).bind("change", function(event, ui) {
							 var action = event.target.value;
							 var harmonogramId = item.id;
							 if (action == 'edit') {
								 thisObj.createEditWindow(harmonogramId);
								 
							 } else if(action == 'delete') {
								thisObj.createDeleteWindow(harmonogramId);
							 }
						});
					});
				}
			});
		},
		bindAddWindowToButton : function(buttonId) {
			$(document).delegate(buttonId, 'click', function() {
				App.doGetRequestText({
					url: 'harmonogram!add.action',
					onSucces: function(response) {
						$('<div>').simpledialog2({
						    mode: 'blank',
						    headerText: 'Nowy harmonogram',
						    headerClose: false,
						    blankContent : response.replace(/\\n/g, ''),
						    fullScreen: true,
							fullScreenForce: true
			  			})
					}
				});		
			});
		},
		createKursanciList: function(selectFieldId, kursanciId) {
			App.doGetRequestJson({
				url: 'harmonogram!listKursanci.action',
				onSucces: function(response) {
					var html ='';
				    $.each(response, function(index, item) {
				        html += '<option value="' + item.id + '">' + item.imie + ' ' + item.nazwisko +  '</option>';
				    });
				    $('#' + selectFieldId).find('option').remove().end();
				    $('#' + selectFieldId).append(html).trigger('create');
				    $('#' + selectFieldId).selectmenu('refresh');
				    
					for (var i = 0; i< kursanciId.length; i++) {
						$("#" + selectFieldId + " option[value='" + kursanciId[i] + "']").attr("selected", "selected");
					}

					$('#' + selectFieldId).selectmenu("refresh", true);
				}
			});
		},
		createPlacManewrowyList: function(selectFieldId, placManewrowyId) {
			App.doGetRequestJson({
				url: 'harmonogram!listRezerwacjaPlacu.action',
				onSucces: function(response) {
					var html ='<option value="0" data-placeholder="true">Dodaj plac manewrowy</option><option value="0">Brak</option>';
				    $.each(response, function(index, item) {
				        html += '<option value="' + item.id + '">' + item.displayName + '</option>';
				    });
				    $('#' + selectFieldId).find('option').remove().end();
				    $('#' + selectFieldId).append(html).trigger('create');
				    $('#' + selectFieldId).selectmenu('refresh');
				    
				    if (placManewrowyId != 0) {
				    	$("#" + selectFieldId + " option[value='" + placManewrowyId + "']").attr("selected", "selected");
				    	$('#' + selectFieldId).selectmenu("refresh", true);
				    }
				}
			});
		}
	}
}